package router

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"web_api_gin/controller"
	admin "web_api_gin/controller/admin"
	index "web_api_gin/controller/index"
)

//LoadRoutes load the route
func LoadRoutes(router *gin.Engine) {
	router.NoRoute(controller.NOTFOUND)

	//后台路由分组
	adminRouter := router.Group("/admin")
	{
		//后台用户登录部分
		adminLoginRouter := adminRouter.Group("/login")
		{
			adminLoginRouter.POST("/account", admin.LoginApi.Account)
			adminLoginRouter.POST("/logout", admin.LoginApi.Logout)
		}
		//后台用户部分
		adminUserRouter := adminRouter.Group("/user")
		{
			adminUserRouter.GET("/current", admin.UserApi.Current)
			adminUserRouter.POST("/update", admin.UserApi.Update)
			adminUserRouter.POST("/reset-pwd", admin.UserApi.ResetPwd)
			adminUserRouter.GET("/get-config", admin.UserApi.GetConfig)
			adminUserRouter.GET("/art-list", admin.UserApi.Articles)
		}
		//后台菜单分组部分
		adminSysMenuGroupRouter := adminRouter.Group("/sys-menu-group")
		{
			adminSysMenuGroupRouter.GET("/index", admin.SysMenuGroupApi.Index)
			adminSysMenuGroupRouter.POST("/save", admin.SysMenuGroupApi.Save)
			adminSysMenuGroupRouter.POST("/destroy", admin.SysMenuGroupApi.Destroy)
		}
		//后台菜单部分
		adminSysMenuRouter := adminRouter.Group("/sys-menu")
		{
			adminSysMenuRouter.GET("/index", admin.SysMenuApi.Index)
			adminSysMenuRouter.POST("/save", admin.SysMenuApi.Save)
			adminSysMenuRouter.POST("/destroy", admin.SysMenuApi.Destroy)
			adminSysMenuRouter.POST("/set-order", admin.SysMenuApi.SetOrder)
		}
		//后台权限管理部分
		adminSysPermRouter := adminRouter.Group("/sys-permission")
		{
			adminSysPermRouter.GET("/index", admin.SysPermissionApi.Index)
			adminSysPermRouter.POST("/save", admin.SysPermissionApi.Save)
			adminSysPermRouter.POST("/destroy", admin.SysPermissionApi.Destroy)
			adminSysPermRouter.POST("/set-order", admin.SysPermissionApi.SetOrder)
		}
		//后台角色管理部分
		adminSysRoleRoter := adminRouter.Group("/sys-role")
		{
			adminSysRoleRoter.GET("/index", admin.SysRoleApi.Index)
			adminSysRoleRoter.POST("/save", admin.SysRoleApi.Save)
			adminSysRoleRoter.POST("/destroy", admin.SysRoleApi.Destroy)
		}
		//后台用户管理
		adminSysUserRouter := adminRouter.Group("/sys-user")
		{
			adminSysUserRouter.GET("/index", admin.SysUserApi.Index)
			adminSysUserRouter.POST("/save", admin.SysUserApi.Save)
			adminSysUserRouter.POST("/disable", admin.SysUserApi.Disable)
			adminSysUserRouter.POST("/enable", admin.SysUserApi.Enable)
		}
		//后台日志接口
		adminRouter.GET("/sys-opt-log/index", admin.SysOptLogApi.Index)
		//后台文件接口
		adminSysFileRouter := adminRouter.Group("/sys-file")
		{
			adminSysFileRouter.GET("/index", admin.SysFileApi.Index)
		}
		//后台省市区列表
		adminRouter.GET("/geographic/get-list", admin.GeographicApi.GetList)
	}
	//前台路由分组
	indexRouter := router.Group("/index")
	{
		//后台首页部分
		indexIndexRouter := indexRouter.Group("/index")
		{
			indexIndexRouter.GET("/index", index.HomeApi.Index)
		}
	}
	//默认首页重定向到首页
	router.GET("/", func(c *gin.Context) {
		c.Redirect(http.StatusMovedPermanently, "/index/index/index")
	})
}
